--[[
	Project.: Broker: ButtonFacade
	File....: Core.lua
	Version.: 30
	Author..: StormFX
]]

if not ButtonFacade then return end

-- [ Libraries ] --

local LDB = LibStub("LibDataBroker-1.1")
local Icon = LibStub("LibDBIcon-1.0", true)

-- [ Set Up ] --

local BBF = LibStub("AceAddon-3.0"):NewAddon("Broker_ButtonFacade", "AceConsole-3.0")
local BF = LibStub("AceAddon-3.0"):GetAddon("ButtonFacade")

-- [ Localization ] --

-- Hard-code enUS/enGB.
local L = {
	["Click to open the options window."] = "Click to open the options window.",
}
-- Automatically inject all other locales. Please use the localization application on WoWAce.com to update these.
-- http://www.wowace.com/projects/buttonfacade/localization/namespaces/buttontest/
do
	local LOC = GetLocale()
	if LOC == "deDE" then
-- L["Click to open the options window."] = "Click to open the options window."

	elseif LOC == "esES" then
-- L["Click to open the options window."] = "Click to open the options window."

	elseif LOC == "esMX" then
-- L["Click to open the options window."] = "Click to open the options window."

	elseif LOC == "frFR" then
L["Click to open the options window."] = "Clic gauche pour ouvrir la fenêtre des options."

	elseif LOC == "koKR" then
-- L["Click to open the options window."] = "Click to open the options window."

	elseif LOC == "ruRU" then
-- L["Click to open the options window."] = "Click to open the options window."

	elseif LOC == "zhCN" then
-- L["Click to open the options window."] = "Click to open the options window."

	elseif LOC == "zhTW" then
L["Click to open the options window."] = "左擊打開選項視窗。"

	end
end

-- [ Local Variables ] --

local db

-- [ Local Functions ] --

-- Toggles the minimap icon.
local function ToggleIcon()
	if Icon then
		db.hide = not db.hide
		if db.hide then
			Icon:Hide(BBF.name)
		else
			Icon:Show(BBF.name)
		end
	end
end

-- [ Core Methods ] --

-- Initialize the add-on.
function BBF:OnInitialize()
	-- Validate the DB.
	if not BrokerBFDB then
		BrokerBFDB = {}

		-- Defaults
		BrokerBFDB = {
			hide = true,
			minimapPos = 220,
			radius = 80,
		}
	end

	-- Local copy of our DB.
	db = BrokerBFDB
end

-- Enable function.
function BBF:OnEnable()
	if LDB then
		self.obj = LDB:NewDataObject(self.name, {
			type  = "launcher",
			label = select(2,GetAddOnInfo("ButtonFacade")),--"ButtonFacade",
			icon  = "Interface\\Addons\\ButtonFacade\\Broker_ButtonFacade\\Icon",
			tocname = "ButtonFacade",
			OnClick = function(self, button)
				if button == "LeftButton" or button == "RightButton" then
					BF:OpenOptions()
				end
			end,
			OnTooltipShow = function(Tip)
				if not Tip or not Tip.AddLine then return end
				Tip:AddLine("ButtonFacade")
				Tip:AddLine(L["Click to open the options window."], 1, 1, 1)
			end,
		})
		if Icon then
			Icon:Register(self.name, self.obj, db)
			self:RegisterChatCommand("bficon", function() ToggleIcon() end)
		end
	end
end
